<?php
require('../include/init.inc.php');
$method = $title = $keyword = $desc = $pcwidth = $pcheight = $mheight = $bq = '';
extract($_REQUEST, EXTR_IF_EXISTS);

if (Common::isPost()) {
    $update_data = array();
    if (!empty($title)) {
        $update_data['title'] = $title;
    }
    if (!empty($keyword)) {
        $update_data['kewords'] = $keyword;
    }
    if (!empty($desc)) {
        $update_data['description'] = $desc;
    }
    if (!empty($pcwidth)) {
        $update_data['width'] = $pcwidth;
    }
    if (!empty($pcheight)) {
        $update_data['height'] = $pcheight;
    }
    if (!empty($mheight)) {
        $update_data['min_height'] = $mheight;
    }
    if (!empty($bq)) {
        $update_data['store_footer'] = $bq;
    }


    //先检查没有配置就是插入


    $ret = Shop::getInfo();
    if ($ret) {
        $result = Shop::updateInfo($update_data, $ret['id']);
    } else {
//        $data = array("title" => $title, "kewords" => $keyword, "description" => $desc, "width" => $pcwidth, "height" => $pcheight, "min_height" => $mheight, "store_footer" => $bq);
        $result = Shop::add($update_data);
    }


    if ($result) {
        SysLog::addLog(UserSession::getUserName(), 'MODIFY', 'Shop', $title, json_encode($update_data));
        Common::exitWithSuccess('更新完成', 'one_page_shop/shop.php');
    } else {
        OSAdmin::alert("error");
    }
}

Template::display('one_page_shop/shop.tpl');